package com.meixiang.activity.account.myShopper;

import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lzy.okhttputils.model.HttpParams;
import com.meixiang.R;
import com.meixiang.entity.myOrder.RefundDetail;
import com.meixiang.global.Config;
import com.meixiang.http.HttpCallBack;
import com.meixiang.http.HttpUtils;
import com.meixiang.main.BaseActivity;
import com.meixiang.tool.Tool;
import com.meixiang.util.AbJsonUtil;
import com.meixiang.util.AbStrUtil;

import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * @author yinsujun  Created at 2016/5/10 14:06
 *         退款详情
 */
public class OrderRefundActivity extends BaseActivity {
    @Bind(R.id.order_refund_tv_money)
    TextView tvMoney;
    @Bind(R.id.order_refund_tv_return_account)
    TextView tvReturnAccount;
    @Bind(R.id.order_refund_tv_apply_time)
    TextView tvApplyTime;
    @Bind(R.id.order_refund_tv_account_time)
    TextView tvAccountTime;
    @Bind(R.id.order_refund_tv_first)
    TextView tvFirst;
    @Bind(R.id.order_refund_tv_second)
    TextView tvSecond;
    @Bind(R.id.order_refund_tv_three)
    TextView tvThree;
    @Bind(R.id.order_refund_tv_four)
    TextView tvFour;
    @Bind(R.id.order_refund_iv_first)
    ImageView ivFirst;
    @Bind(R.id.order_refund_view_first)
    View viewFirst;
    @Bind(R.id.order_refund_iv_second)
    ImageView ivSecond;
    @Bind(R.id.order_refund_view_second)
    View viewSecond;
    @Bind(R.id.order_refund_iv_three)
    ImageView ivThree;
    @Bind(R.id.order_refund_view_three)
    View viewThree;
    @Bind(R.id.order_refund_iv_four)
    ImageView ivFour;
    private String refundId;
    private List<TextView> textViewList;
    private List<ImageView> imageViews;
    private List<View> views;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_order_refund);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initTitle() {
        setTitle("退款详情");

    }

    @Override
    protected void initView() {
        refundId = getIntent().getStringExtra("refundId");
        textViewList=new ArrayList<>();
        imageViews=new ArrayList<>();
        views=new ArrayList<>();

        textViewList.add(tvFirst);
        textViewList.add(tvSecond);
        textViewList.add(tvThree);
        textViewList.add(tvFour);
        imageViews.add(ivFirst);
        imageViews.add(ivSecond);
        imageViews.add(ivThree);
        imageViews.add(ivFour);
        views.add(viewFirst);
        views.add(viewSecond);
        views.add(viewThree);
    }

    @Override
    protected void setData() {
        getRefundData();

    }

    private void getRefundData() {
        String url = Config.GET_ORDER_REFUND_DETAIL;
        HttpParams params = new HttpParams();
        params.put("refundId", refundId);
        HttpUtils.post(url, params, new HttpCallBack(OrderRefundActivity.this) {
            @Override
            public void onSucceed(JSONObject result, String code, String message) {
                RefundDetail refundDetail = AbJsonUtil.fromJson(result.toString(), RefundDetail.class);
                setRefundDetail(refundDetail);
            }

            @Override
            public void onError(String code, String message) {
                Tool.showTextToast(context, message);

            }
        });
    }

    private void setRefundDetail(RefundDetail refundDetail) {
        tvMoney.setText(refundDetail.getRefundAmount());
        tvReturnAccount.setText(refundDetail.getRefundAccount());
        tvAccountTime.setText(refundDetail.getTransferTime());
        tvApplyTime.setText(refundDetail.getApplyTime());
        if(!AbStrUtil.isEmpty(refundDetail.getRefundId())){
            int position=Integer.parseInt(refundDetail.getRefundId());
//            for(int i=0;i<position;i++){
//                views.get(position).setBackgroundColor(ContextCompat.getColor(context,R.color.order_green_color));
//            }
            if(position==1){
                return;
            }
            for(int i=1;i<position+1;i++){
                textViewList.get(i).setTextColor(ContextCompat.getColor(context,R.color.order_green_color));
                imageViews.get(i).setImageResource(R.mipmap.ic_order_refund_now);
                if(i>0){
                    views.get(i-1).setBackgroundColor(ContextCompat.getColor(context,R.color.order_green_color));
                }
            }
        }

    }

    @Override
    public void onClick(View v) {

    }
}
